package cn.dhnep.demo.util;

import cn.dhnep.demo.pojo.entity.LongitudeAndLatitudeEntity;



/**
 * @Author 邱文彬
 * @Date 2021/11/9 12:30
 * @Version 1.0
 */

public class LongitudeAndLatitude {


    public static double getLongitudeAndLatitude(LongitudeAndLatitudeEntity LongitudeAndLatitudeEntityOne, LongitudeAndLatitudeEntity LongitudeAndLatitudeEntityTwo) {

        double radLat1 = Math.toRadians(LongitudeAndLatitudeEntityOne.getLatitude().doubleValue());

        double radLat2 = Math.toRadians(LongitudeAndLatitudeEntityTwo.getLatitude().doubleValue());

        double a = radLat1 - radLat2;

        double b = Math.toRadians(LongitudeAndLatitudeEntityOne.getLongitude().doubleValue()) - Math.toRadians(LongitudeAndLatitudeEntityTwo.getLongitude().doubleValue());

        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1)

                * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));

        s = s * 6378137.0;// 取WGS84标准参考椭球中的地球长半径(单位:m)

        s = Math.round(s * 10000) / 10000;

        return s;

    }




}
